package com.cskaoyan.service;

import com.cskaoyan.bean.wx.vo.UserIndexVo;
import com.cskaoyan.bean.wx.vo.UserOrderStatusVo;
import com.cskaoyan.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    OrderMapper orderMapper;

    @Override
    public UserIndexVo selectUserIndexByUserId(Integer userId) {
        List<UserOrderStatusVo> numlists =orderMapper.selectUserIndexByUserId(userId);
        Integer commentBum = orderMapper.selectComments(userId);
        UserIndexVo userIndexVo = new UserIndexVo();
        userIndexVo.setUnpaid(0);
        userIndexVo.setUncomment(commentBum);
        userIndexVo.setUnrecv(0);
        userIndexVo.setUnship(0);
        for (UserOrderStatusVo numlist : numlists) {
            Integer status = numlist.getOrderStatus();
            Integer num = numlist.getNum();
            if (status.equals(101)) {
                userIndexVo.setUnpaid(num);
            }else if(status.equals(301)){
                userIndexVo.setUnrecv(num);
            }else if(status.equals(201)){
                userIndexVo.setUnship(num);
            }
        }
        return userIndexVo;
    }
}
